﻿Ext.require([
    'Twi.Msg',
    'Twi.Tbar',
    'Twi.QuickAjax',
    'Twi.QuickGrid',
    'Twi.QuickPagingGrid',
    'Twi.QuickWin',
    'BIM.store.User',
    'TAB.view.user.ConditionForm'
]);

Ext.onReady(function () {
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';
    twiSelf.init();
});

Twi.TAB.UserComplexQuery = {

    Vars: {
        conditionForm: null,
        userGrid: null,
        userMappingName: 'SM010',
        userViewMappingName: 'SM010-V1'
    } //end Vars

    , init: function () {
        twiVars.conditionForm = twiSelf.Form.createConditionForm();
        twiVars.userGrid = twiSelf.Grid.createUserGrid();
    } //end init;

    , Grid: {
        createUserGrid: function () {
            var store = Ext.create("BIM.store.User");
            store.proxy.extraParams.mn2 = "GetByComplexCondition";
            store.load();
            var grid = Ext.create("Twi.QuickPagingGrid", {
                title: '用户列表',
                // forceFit: true,
                store: store,
                renderTo: 'userGrid',
                resizable: true,
                viewConfig: {
                    stripeRows: true
                },
                columns: [{
                    xtype: 'rownumberer'
                }, {
                    header: '姓名',
                    dataIndex: 'FREALNAME',
                    flex: 1
                }, {
                    header: '用户名',
                    dataIndex: 'FNAME',
                    flex: 1
                }, {
                    header: '工号',
                    dataIndex: 'FJOBNUMBER',
                    flex: 1
                }, {
                    header: '性别',
                    dataIndex: 'FSEX',
                    flex: 1
                }, {
                    header: '手机号',
                    dataIndex: 'FPHONENUMBER',
                    flex: 1
                }, {
                    header: '部门',
                    dataIndex: 'DEPARTMENTNAME',
                    flex: 1
                }, {
                    header: '职务',
                    dataIndex: 'FDUTYNAME',
                    flex: 1
                }, {
                    header: '状态',
                    dataIndex: 'FISACTIVE',
                    renderer: function (value) {
                        if (value == "1") {
                            return '正常';
                        }
                        else if (value == "0") {
                            return '<span style="color:red;">锁定</span>';
                        }
                        return value;
                    },
                    flex: 1
                }, {
                    header: '排序',
                    dataIndex: 'FSORT',
                    width: 60
                }]
            });

            return grid;

        } //end createUserGrid
    } //end Grid

    , Form: {
        createConditionForm: function () {
            var form = Ext.create('TAB.view.user.ConditionForm', {
                title: '查询条件',
                renderTo: 'conditionForm',
                height: ($(document).height() - Twi.TokenHeight - 3),
                btnQuery: function (values) {
                    if (values.length > 0) {
                        var data = {
                            TableName: twiVars.userViewMappingName,
                            OrderFields: 'FSORT',
                            Condition: {
                                FIsDeleted: 0
                            },
                            ComplexCondition: Ext.encode(values)
                        };
                        twiVars.userGrid.store.proxy.extraParams.data = Ext.encode(data);
                    }
                    else {
                        var data = {
                            TableName: twiVars.userViewMappingName,
                            OrderFields: 'FSORT',
                            Condition: {
                                FIsDeleted: 0
                            }
                        };
                        twiVars.userGrid.store.proxy.extraParams.data = Ext.encode(data);
                    }
                    twiVars.userGrid.store.loadPage(1);
                }
            });
            return form;
        } //end createConditionForm

    } //end Form


};   //end Twi.TAB.UserComplexQuery

var twiSelf = Twi.TAB.UserComplexQuery;
var twiVars = twiSelf.Vars;